package weaver.interfaces.jjy.duss.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.jjy.duss.cscg.Z_IF_OPS130;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-01-14
 * @Description: 新店、改造店营销/促销规划申请流程回传SAP
 * @ModifyLog:
 **/

public class WeaYYxdgzdcxAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        RecordSet rs2 = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用Action: WeaYYxdgzdcxAction");
        User user = requestInfo.getRequestManager().getUser();
        int userid = user.getUID();
        String currentDate = requestInfo.getRequestManager().getCurrentDate().replaceAll("-","");
        String currentTime = requestInfo.getRequestManager().getCurrentTime().replaceAll(":","");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        rs.executeQuery("select SJDQNO,REL_FLAG from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("select SJDQNO,REL_FLAG from " + tablename + " where requestid=?", requestid);
        rs.next();
        String SJDQNO = Util.null2String(rs.getString("SJDQNO"));//档期编号
        String REL_FLAG = Util.null2String(rs.getString("REL_FLAG"));//审批结果
        rs2.executeQuery("select workcode from hrmresource  where id=?",userid);
        baseBean.writeLog("select workcode from hrmresource  where id=?",userid);
        String PERNR = Util.null2String(rs2.getString("workcode"));//人员编号
        Map<String, String> map = new HashMap();
        map.put("SJDQNO", SJDQNO); //实际档期编号
        map.put("REL_FLAG", REL_FLAG);   //审批标记
        map.put("REL_USER", PERNR);   //审批人员
        map.put("REL_DATUM", currentDate);  //审批日期
        map.put("REL_UZEIT", currentTime);  //审批时间
        baseBean.writeLog("相关参数:" + map.toString());
       try{
           Z_IF_OPS130 if_ops130 = new Z_IF_OPS130();
           Map resultMap = if_ops130.execute(map);
           String flag = (String) resultMap.get("flag");
           String message = (String) resultMap.get("message");
           baseBean.writeLog("SAP返回结果——flag:" + flag + ";message:" + message);
           if("s".equalsIgnoreCase(flag)){
               return Action.SUCCESS;
           }else {
               requestInfo.getRequestManager().setMessageid("111111");
               requestInfo.getRequestManager().setMessagecontent(message);
               return Action.FAILURE_AND_CONTINUE;
           }
       } catch (Exception e) {
           e.printStackTrace();
           baseBean.writeLog("异常参考:" + e);
           requestInfo.getRequestManager().setMessageid("111111");
           requestInfo.getRequestManager().setMessagecontent(e.getMessage());
           return Action.FAILURE_AND_CONTINUE;
       }
    }
}
